//
//  HBGetUserInfoManager.m
//  CreditManger
//
//  Created by chaiyanan on 15/11/5.
//  Copyright © 2015年 jinxin. All rights reserved.
//

#import "HBGetUserInfoManager.h"
#import "HBLoginManager.h"

#import "HBGetUserInfoParam.h"
#import "HBGetUserInfoParser.h"


@implementation HBGetUserInfoManager

+ (void)requestToGetUserInfoWithResult:(void (^)(BOOL, NSString *, NSError *))result
{
    
    HBGetUserInfoParam *param = [[HBGetUserInfoParam alloc]init];
    param.uid = [HBLoginManager sharedHBLoginManager].currentUserInfo.uid;
    param.token = [HBLoginManager sharedHBLoginManager].currentUserInfo.token;
    HBGetUserInfoParser *parser = [[HBGetUserInfoParser alloc]init];
    [NetCenter getDataFromURL:Method_getUserInfo
                        params:param
                        parser:parser
                        result:^(ParserResult *myResult)
     {
         if (myResult.code ==0 )
         {
             HBLoginUserInfo *info = (HBLoginUserInfo *)myResult.result;
             info.token = [HBLoginManager sharedHBLoginManager].currentUserInfo.token;
             [HBLoginManager cacheCurrentUserToUserDefault:info];
             [[NSNotificationCenter defaultCenter]postNotificationName:@"UpDataInformation" object:nil];
             if (result)
             {
                 result(YES, @"", nil);
             }
         }
         else
         {
             if (result)
             {
                 result(NO, myResult.message, nil);
             }
         }
         
     } failure:^(NSError *error)
     {
         if (result)
         {
             result(NO, @"", error);
         }
     }];
    
    
}

@end
